package studentSystem;

import java.util.ArrayList;

public class Management {
    private ArrayList<Students> list= new ArrayList<Students>();
    public Management() {
    }

    public ArrayList<Students> getList() {
        return list;
    }

    public void setList(ArrayList<Students> list) {
        if(list!=null) {
            this.list = list;
        }
    }

    public void addStu(Students students){
        boolean listHaveSameId=false;
        if(students!=null&&students.judgeLegal()) {
            for (Students value : this.list) {
                if (value.getId() == students.getId()) {
                    listHaveSameId = true;
                    break;
                }
            }
            if (listHaveSameId) {
                System.err.println("错误[学号:" + students.getId() + "已存在，无法添加" + students.getName() + "]");
            } else {
                this.list.add(students);
            }
        }else{
            System.err.println("错误[此学生信息非法:"+students.getId()+" "+students.getName()+" "+students.getSex()+"]");
        }
    }
    public void removeStuByID(int id){
        for (int i = 0; i < this.list.size(); i++) {
            if(this.list.get(i).getId()==id){
                this.list.remove(i);
            }
        }
    }
    public Students findStuByID(int id){
        Students stu=new Students();
        for (Students students : this.list) {
            if (students.getId() == id) {
                stu = students;
            }
        }
        return stu;
    }
    public void printAllStu(){
        for (Students students : this.list) {
            students.introduce();
        }
    }
}
